package com.vastcom.bmi.action;
import java.lang.*;
import com.vastcom.bmi.to.Parm;
import com.vastcom.bmi.vo.Result;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
public class PublicAction {
@GetMapping("hello")
    @ResponseBody
    public String helloword() throws Exception {
     return "Hello Word SpringBoot";
}
@PostMapping("bmivalue")
    @ResponseBody
    public Result bmivalue(@RequestBody Parm parm) throws Exception{
    float sgf=Float.parseFloat(parm.getSg());
    float tzf=Float.parseFloat(parm.getTz());
    float result=tzf/(sgf*sgf);
    String suggest="";
        if(result<=18.4){
            suggest="thin";
        }
        else if(result>=18.5&&result<=23.9){
            suggest="normal";
        }
        else if(result>=24&&result<=27.9){
            suggest="overweight";
        }
        else {
            suggest="fat";
        }
    Result r=new Result();
        r.setSg(parm.getSg());
        r.setTz(parm.getTz());
       r.setResult(result);
       r.setSuggest(suggest);



    return r;
}
}
